package com.kgc.scd.controller;

import com.kgc.scd.bean.IndexPic;
import com.kgc.scd.service.IndexPicService;
import com.kgc.scd.service.IndexSearchService;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: com.kgc.scd.controller
 * @author: HarryXzy
 * @create: 2022-06-16 14:40
 * @description:
 **/
@RestController
@Api(tags = "02、首页轮播图操作入口")
public class IndexPicController {
    @Autowired
    private IndexPicService indexPicService;

    @ApiOperation(value = "获取所有的首页轮播图", notes = "获取所有的首页轮播图")
    // 返回状态说明
    @ApiResponses({
            @ApiResponse(code = 500, message = "系统错误"),
            @ApiResponse(code = 200, message = "成功")
    })
    @PostMapping("/allIndexPic")
    public RequestResult<Object> allIndexPic(){
        Map<String, Object> result = indexPicService.allIndexPic();
        if (result.get("code").equals("200")) {
            return ResultBuildUtil.success(result.get("data"));
        }
        return ResultBuildUtil.fail(result.get("code").toString(), result.get("msg").toString());
    }

    @ApiOperation(value = "添加首页轮播图", notes = "添加首页轮播图")
    // 返回状态说明
    @ApiResponses({
            @ApiResponse(code = 500, message = "系统错误"),
            @ApiResponse(code = 200, message = "成功")
    })
    @PostMapping("/addIndexSearch")
    public RequestResult<Object> addIndexSearch(@RequestBody IndexPic indexPic){
        Map<String, Object> result = indexPicService.addIndexSearch(indexPic);
        if (result.get("code").equals("200")) {
            return ResultBuildUtil.success(result.get("data"));
        }
        return ResultBuildUtil.fail(result.get("code").toString(), result.get("msg").toString());
    }



    @ApiOperation(value = "删除轮播图", notes = "删除轮播图")
    // 返回状态说明
    @ApiResponses({
            @ApiResponse(code = 500, message = "系统错误"),
            @ApiResponse(code = 200, message = "成功")
    })
    @PostMapping("/deleteIndexSearch")
    public RequestResult<Object> deleteIndexSearch(@RequestParam String indexPicId){
        Map<String, Object> result = indexPicService.deleteIndexSearch(indexPicId);
        if (result.get("code").equals("200")) {
            return ResultBuildUtil.success(result.get("data"));
        }
        return ResultBuildUtil.fail(result.get("code").toString(), result.get("msg").toString());
    }




    @ApiOperation(value = "修改轮播图的顺序", notes = "修改轮播图的顺序")
    // 返回状态说明
    @ApiResponses({
            @ApiResponse(code = 500, message = "系统错误"),
            @ApiResponse(code = 200, message = "成功")
    })
    @PostMapping("/changePicSort")
    public RequestResult<Object> changePicSort(@RequestParam String indexPicId,@RequestParam Integer sort){
        Map<String, Object> result = indexPicService.changePicSort(indexPicId,sort);
        if (result.get("code").equals("200")) {
            return ResultBuildUtil.success(result.get("data"));
        }
        return ResultBuildUtil.fail(result.get("code").toString(), result.get("msg").toString());
    }




}
